<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/include/header.jsp"%>
<title>查询字典列表</title>
</head>
<body>
	<div class="main_panel">
		<div class="ch_panel" id="queryDiv">
			<input type="hidden" data-qname="CSRFToken" id="CSRFToken" value="${csrfToken}" id="csrfToken" />
			<table class="c_table">
				<tr>
					<td>
						<button class="a_btn" id="addBtn">新增</button>
					</td>
					<td class="t_l">
						字典组别：<select class="input_txt" data-qname="dicGroupType" id="dicGroupType" value="">
							<c:forEach items="${dicGroupTypeMap }" var="obj">
								<option <c:if test="${dicGroupType eq obj.key }">selected="selected"</c:if> value="${obj.key }">${obj.value }</option>
							</c:forEach>
						</select> 
						&nbsp;&nbsp; 字典代码：
						<input type="text" data-qname="dicCode" id="dicCode" value="" class="input_txt" style="width: 180px" />
						&nbsp;&nbsp; 字典名称：
						<input type="text" data-qname="dicName" id="dicName" value="" class="input_txt" style="width: 180px" />
					</td>
					<td class="t_r">
						<input type="button" value="查询" id="searchBtn" class="c_btn" />
					</td>
				</tr>
			</table>
		</div>
		<table id="tbwrap" class="table table-border table-bordered table-bg m_t10 hovaertable"></table>
		<div class="page eui-pager-custom" id="j_pager"></div>
	</div>

	<script type="text/html" id="tb_template">
		<thead>
			<tr>
				<th>字典组别</th>
				<th>代码</th>
				<th>名称</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody data-type="body">
			<!if(result.dataList.length>0) { !>
				<!for(var i=0,len=result.dataList.length;i<len;i++){
					var item = result.dataList[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<td title="<!=item["dicGroupName"]!>"><!=item["dicGroupName"]!></td>
					<td title="<!=item["dicCode"]!>"><!=item["dicCode"]!></td>
					<td title="<!=item["dicName"]!>"><!=item["dicName"]!></td>
					<td>
						<a title="详情" data-value="<!=item["uuid"]!>" class="view" style="text-decoration: none;margin-right: 10px;">
							<i class="Hui-iconfont">&#xe665;</i>
						</a>
						<a title="编辑" data-value="<!=item["uuid"]!>" class="edit" style="text-decoration: none;margin-right: 10px;">
							<i class="Hui-iconfont">&#xe6df;</i>
						</a>
						<a title="删除" data-value="<!=item["uuid"]!>" class="delete" style="text-decoration: none">
							<i class="Hui-iconfont">&#xe6e2;</i>
						</a>
					</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="10"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>



	<script type="text/javascript">
		$(function() {

			//ajax请求添加等待图片
			$(document).ajaxStart(function() {
				ZENG.msgbox.show(" 正在加载中，请稍后...", 6, 8000);
			});

			$(document).ajaxComplete(function() {
				ZENG.msgbox.hide();
			});

			// 添加
			$("#addBtn").click(function() {
				parent.member_add("新增字典信息", "${ctx}/dicObj/toAdd?dicGroupType=" + $("#dicGroupType").val(),560,260);
			});
			
			// 编辑
			$("#tbwrap").delegate(".edit", "click", function() {
				//获取主键
				var uuid = $(this).data("value");
				parent.member_add("修改字典信息", "${ctx}/dicObj/toEdit?uuid="+uuid,560,260);
				
			});
			
			// 详细
			$("#tbwrap").delegate(".view", "click", function() {
				//获取主键
				var uuid = $(this).data("value");
				parent.member_add("查看字典详细", "${ctx}/dicObj/view?uuid="+uuid,560,200);
				
			});
			
			// 4、删除
			$("#tbwrap").delegate(".delete", "click", function() {
				var uuid = $(this).data("value");
			
				if (confirm('确定删除？')) {
					$.post("${ctx}/dicObj/delete", { uuid : uuid, CSRFToken : $("#CSRFToken").val()}, function(result) {
						if ("succ" == result) {
							alert("操作成功");
							// 刷新列表页面
							search();
						} else {
							alert(result);
						}
					}, "json");
				}
			
			});
			// 5、查询
			$("#searchBtn").click(function() {
				search();
			});
			
			// 页面加载完成调用查询分页
			search();
		});
	</script>

	<script type="text/javascript">
		function search() {
			// 这里放包含查询条件的DIV
			var paramData = easyUtils.getQueryDivDefault("queryDiv");

			seajs.use([ "component/table" ], function(uiTable) {
				
				 seajs.use(["component/table"], function (uiTable) {
				        $.post("${ctx}/dicObj/ajaxPage",paramData,function (result) {
				        	
				        	// 系统有异常信息
				        	if (JSON.stringify(result).indexOf("系统出现异常")>=0) {
				        		alert(result);
				        		return;
				        	}
			            	var table = new uiTable({
			                	"con": "#tbwrap",
			                    "data": {
			                         "result": result
			                    },
			                    "template": "tb_template",
			                    "pager": {
			                    	"con": "#j_pager",
			                        "data": {
			                        	"currentPage": result.currentPage,
			                            "pageCount": result.pageCount,
			                            "rowCount": result.rowCount
			                        },
			                        template: '<a title="首页" class="page_first" data-role="first" href="#"></a><a title="上一页" class="page_prev" href="#" data-role="prev"></a><div data-value="pageNum"></div><a title="下一页" class="page_next" href="#" data-role="next"></a><a title="尾页" class="page_last" href="#" data-role="last"></a> 共<span data-target="rowCount"></span>条   共<span data-target="pageCount"></span>页 跳转到 <input type="text" data-target="input" class="page_input"/><a href="#" data-role="go" class="go">GO</a>'
			                    }
			                });
			
			                table.getPager().bind("changePage", function (event, page, hander) {
			                	$.post("${ctx}/dicObj/ajaxPage", {page:page,dicGroupType:$("#dicGroupType").val(),dicCode:$("#dicCode").val(),dicName:$("#dicName").val()} ,function (result) {
				                    	if (JSON.stringify(result).indexOf("系统出现异常")>=0) {
							        		alert(result);
							        		return;
							        	}
				                    	
				    		        	
				                    	table.render({ "result": result});
					                    hander({"currentPage": result.currentPage, "pageCount": result.pageCount, "rowCount": result.rowCount });
				                 	}, 
				                "json");
			                });
			        	}, "json");
			      	});
			});
		}
	</script>
	<%@ include file="/include/footer.jsp"%>
</body>
</html>
